package com.xing.bean;


import com.xing.bean.api.IBeanFactory;
import com.xing.bean.api.IBeanFactoryAware;
import com.xing.bean.api.IBeanPostProcessor;
import com.xing.bean.api.IBeanProcessorChain;
import com.xing.bean.exception.BeanProcessException;

public class BeanFactoryInjectProcessor implements IBeanPostProcessor {
	private IBeanFactory beanFactory;
	
	public BeanFactoryInjectProcessor(IBeanFactory beanFactory) {
		this.beanFactory = beanFactory;
	}
	
	public int priority() {
		return 1;
	}

	public <T> T process(T obj, IBeanProcessorChain chain) throws BeanProcessException {
		if(obj instanceof IBeanFactoryAware){
			IBeanFactoryAware aware = (IBeanFactoryAware)obj;
			aware.setBeanFactory(beanFactory);
		}
		return chain.doProcess(obj);
	}

}
